/*
 * @Author: xuxueliang
 * @Date: 2022-05-30 21:33:48
 * @LastEditTime: 2022-06-21 17:17:45
 * @LastEditors: xuxueliang
 * @Description:
 */
function isPcOrMb() {
  var userAgentInfo = navigator.userAgent;
  var Agents = ["Android", "iPhone",
     "SymbianOS", "Windows Phone",
     "iPad", "iPod"];
  var flag = true;
  for (var v = 0; v < Agents.length; v++) {
     if (userAgentInfo.indexOf(Agents[v]) > -1) {
        flag = false;
        break;
     }
  }
  return flag;
}
if(isPcOrMb()){
  document.querySelector('html').classList.add('is-pc')
}else{
  document.querySelector('html').classList.add('is-wap')
}
$(function () {
  const videoButton = $('.video-play-action');
  $('.video-play-action').find('video').removeAttr('controls');
  // 监听开始
  videoButton.find('video').on('play', function () {
    $(this).prev().fadeOut(500);
  });

  // 监听暂停
  videoButton.find('video').on('pause', function () {
      $(this).prev().fadeIn(500);
  });
  // videoButton.find('video').on('seeked', function () {
  //   // if(this.setTimeout){
  //   //   clearTimeout(this.setTimeout)
  //   //   this.setTimeout=null
  //   // }
  // });
  // // 点击播放
  // videoButton.on('click','.play',function () {
  //   // if(this.isplay){
  //   //   return
  //   // }
  //   const video = $(this).next()[0];
  //   video.play();
  //   $(video).attr('controls', 'controls');
  //   this.isplay = true;
  // });
   // 点击播放
   videoButton.find('.play').click(function () {
    // if(this.isplay){
    //   return
    // }
    const video = $(this).next()[0];
    video.play();
    $(video).attr('controls', 'controls');
    this.isplay = true;
  });
  //share
  if ($('.icon.share').length) {
    $('.icon.share').click(function () {
      $('.share-fu').fadeIn();
      $('body').addClass('oh');
    });
    $('.share-fu').click(function () {
      $('body').removeClass('oh');
      $('.share-fu').fadeOut();
    });
    let has = localStorage.getItem('hasPop');
    if (has == 1) {
      return;
    }
    let offset = $('.icon.share').offset();
    let img = $(
      '<div class="fixed share-guild dn"><img style="left:' +
        offset.left +
        'px;top:' +
        offset.top +
        'px" src="/static/assets/public/images/firstShowshare.png"/></div>'
    );
    $('body').append(img).addClass('oh');
    setTimeout(() => {
      img.fadeIn();
    }, 500);
    img.click(function () {
      localStorage.setItem('hasPop', 1);
      $('body').removeClass('oh');
      img.fadeOut();
    });
  }
  // if(window.location.href.indexOf('html')>-1){
  //   loadScript('https://cdn.bootcss.com/vConsole/3.2.0/vconsole.min.js').then(() => {
  //     window.vConsole = new window.VConsole()
  //   })
  // }
});
(function () {
  if (
    typeof WeixinJSBridge == 'object' &&
    typeof WeixinJSBridge.invoke == 'function'
  ) {
    handleFontSize();
  } else {
    if (document.addEventListener) {
      document.addEventListener('WeixinJSBridgeReady', handleFontSize, false);
    } else if (document.attachEvent) {
      document.attachEvent('WeixinJSBridgeReady', handleFontSize);
      document.attachEvent('onWeixinJSBridgeReady', handleFontSize);
    }
  }
  function handleFontSize() {
    alert('handleFontSize')
    // 设置网页字体为默认大小
    WeixinJSBridge.invoke('setFontSizeCallback', { fontSize: 0 });
    // 重写设置网页字体大小的事件

    WeixinJSBridge.on('menu:setfont', function () {
      WeixinJSBridge.invoke('setFontSizeCallback', { fontSize: 0 });
    });
    lib.flexible.refreshRem()
    console.log('lib.flexible.refreshRem')
  }
});

let loadScriptUrls = {}
let loadScriptLaoding = {}
/**
 * @name:
 * @description: 获取url
 * @param {*} url
 * @param {*} callback
 * @return {*}
 * @template:
 */
 function loadScript(url) {
  if (loadScriptLaoding[url]) {
    return loadScriptLaoding[url]
  }
  let promise = new Promise((resolve, reject) => {
    if (loadScriptUrls[url]) {
      resolve()
      return
    }
    var script = document.createElement('script')
    script.type = 'text/javascript'
    if (script.readyState) {
      //IE
      script.onreadystatechange = function() {
        if (script.readyState == 'loaded' || script.readyState == 'complete') {
          script.onreadystatechange = null
          loadScriptUrls[url] = true
          delete loadScriptLaoding[url]
          resolve()
        }
      }
    } else {
      //Others: Firefox, Safari, Chrome, and Opera
      script.onload = function() {
        loadScriptUrls[url] = true
        delete loadScriptLaoding[url]
        resolve()
      }
      script.onerror = function() {
        delete loadScriptLaoding[url]
        reject()
      }
    }
    script.src = url
    document.body.appendChild(script)
  })
  loadScriptLaoding[url] = promise
  return promise
}
